<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="潜在客户名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入潜在客户名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="潜在客户年龄" prop="age">
        <el-input
          v-model="queryParams.age"
          placeholder="请输入潜在客户年龄"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="潜在客户微信" prop="wechat">
        <el-input
          v-model="queryParams.wechat"
          placeholder="请输入潜在客户微信"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="潜在客户qq" prop="qq">
        <el-input
          v-model="queryParams.qq"
          placeholder="请输入潜在客户qq"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="潜在客户联系电话" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入潜在客户联系电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="潜在客户工作年限" prop="workYears">
        <el-input
          v-model="queryParams.workYears"
          placeholder="请输入潜在客户工作年限"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="毕业时间" prop="graduationTime">
        <el-date-picker clearable
          v-model="queryParams.graduationTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择毕业时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="来源：他人推荐、公众号" prop="channel">
        <el-input
          v-model="queryParams.channel"
          placeholder="请输入来源：他人推荐、公众号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="推荐人" prop="referrers">
        <el-input
          v-model="queryParams.referrers"
          placeholder="请输入推荐人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="意向程度 0 -- 弱  1 -- 强" prop="degreeIntent">
        <el-input
          v-model="queryParams.degreeIntent"
          placeholder="请输入意向程度 0 -- 弱  1 -- 强"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="意向学科" prop="degreeDiscipline">
        <el-input
          v-model="queryParams.degreeDiscipline"
          placeholder="请输入意向学科"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="意向班级" prop="degreeClasses">
        <el-input
          v-model="queryParams.degreeClasses"
          placeholder="请输入意向班级"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="录入人" prop="entrantTeacher">
        <el-input
          v-model="queryParams.entrantTeacher"
          placeholder="请输入录入人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="咨询老师" prop="consultTeacher">
        <el-input
          v-model="queryParams.consultTeacher"
          placeholder="请输入咨询老师"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="录入时间" prop="entryTime">
        <el-date-picker clearable
          v-model="queryParams.entryTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择录入时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="最后追踪时间" prop="astTraceDate">
        <el-date-picker clearable
          v-model="queryParams.astTraceDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择最后追踪时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="下次追踪时间" prop="nextTraceTime">
        <el-date-picker clearable
          v-model="queryParams.nextTraceTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择下次追踪时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['teacher:prospects:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['teacher:prospects:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['teacher:prospects:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['teacher:prospects:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="prospectsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键id" align="center" prop="id" />
      <el-table-column label="潜在客户名" align="center" prop="name" />
      <el-table-column label="潜在客户年龄" align="center" prop="age" />
      <el-table-column label="潜在客户微信" align="center" prop="wechat" />
      <el-table-column label="潜在客户qq" align="center" prop="qq" />
      <el-table-column label="潜在客户联系电话" align="center" prop="phone" />
      <el-table-column label="潜在客户性别 0 --- 男  1--- 女" align="center" prop="sex" />
      <el-table-column label="潜在客户工作年限" align="center" prop="workYears" />
      <el-table-column label="毕业时间" align="center" prop="graduationTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.graduationTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="来源：他人推荐、公众号" align="center" prop="channel" />
      <el-table-column label="当前状态：0--有意向  1--已经报名  2--无意向" align="center" prop="status" />
      <el-table-column label="是否是老学员推荐
" align="center" prop="isOldCadetsRecom" />
      <el-table-column label="推荐人" align="center" prop="referrers" />
      <el-table-column label="意向程度 0 -- 弱  1 -- 强" align="center" prop="degreeIntent" />
      <el-table-column label="意向学科" align="center" prop="degreeDiscipline" />
      <el-table-column label="意向班级" align="center" prop="degreeClasses" />
      <el-table-column label="录入人" align="center" prop="entrantTeacher" />
      <el-table-column label="咨询老师" align="center" prop="consultTeacher" />
      <el-table-column label="录入时间" align="center" prop="entryTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.entryTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="最后追踪时间" align="center" prop="astTraceDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.astTraceDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="下次追踪时间" align="center" prop="nextTraceTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.nextTraceTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['teacher:prospects:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['teacher:prospects:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改潜在用户对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="潜在客户名" prop="name">
          <el-input v-model="form.name" placeholder="请输入潜在客户名" />
        </el-form-item>
        <el-form-item label="潜在客户年龄" prop="age">
          <el-input v-model="form.age" placeholder="请输入潜在客户年龄" />
        </el-form-item>
        <el-form-item label="潜在客户微信" prop="wechat">
          <el-input v-model="form.wechat" placeholder="请输入潜在客户微信" />
        </el-form-item>
        <el-form-item label="潜在客户qq" prop="qq">
          <el-input v-model="form.qq" placeholder="请输入潜在客户qq" />
        </el-form-item>
        <el-form-item label="潜在客户联系电话" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入潜在客户联系电话" />
        </el-form-item>
        <el-form-item label="潜在客户工作年限" prop="workYears">
          <el-input v-model="form.workYears" placeholder="请输入潜在客户工作年限" />
        </el-form-item>
        <el-form-item label="毕业时间" prop="graduationTime">
          <el-date-picker clearable
            v-model="form.graduationTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择毕业时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="来源：他人推荐、公众号" prop="channel">
          <el-input v-model="form.channel" placeholder="请输入来源：他人推荐、公众号" />
        </el-form-item>
        <el-form-item label="推荐人" prop="referrers">
          <el-input v-model="form.referrers" placeholder="请输入推荐人" />
        </el-form-item>
        <el-form-item label="意向程度 0 -- 弱  1 -- 强" prop="degreeIntent">
          <el-input v-model="form.degreeIntent" placeholder="请输入意向程度 0 -- 弱  1 -- 强" />
        </el-form-item>
        <el-form-item label="意向学科" prop="degreeDiscipline">
          <el-input v-model="form.degreeDiscipline" placeholder="请输入意向学科" />
        </el-form-item>
        <el-form-item label="意向班级" prop="degreeClasses">
          <el-input v-model="form.degreeClasses" placeholder="请输入意向班级" />
        </el-form-item>
        <el-form-item label="录入人" prop="entrantTeacher">
          <el-input v-model="form.entrantTeacher" placeholder="请输入录入人" />
        </el-form-item>
        <el-form-item label="咨询老师" prop="consultTeacher">
          <el-input v-model="form.consultTeacher" placeholder="请输入咨询老师" />
        </el-form-item>
        <el-form-item label="录入时间" prop="entryTime">
          <el-date-picker clearable
            v-model="form.entryTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择录入时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="最后追踪时间" prop="astTraceDate">
          <el-date-picker clearable
            v-model="form.astTraceDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择最后追踪时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="下次追踪时间" prop="nextTraceTime">
          <el-date-picker clearable
            v-model="form.nextTraceTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择下次追踪时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listProspects, getProspects, delProspects, addProspects, updateProspects } from "@/api/teacher/prospects";

export default {
  name: "Prospects",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 潜在用户表格数据
      prospectsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        age: null,
        wechat: null,
        qq: null,
        phone: null,
        sex: null,
        workYears: null,
        graduationTime: null,
        channel: null,
        status: null,
        isOldCadetsRecom: null,
        referrers: null,
        degreeIntent: null,
        degreeDiscipline: null,
        degreeClasses: null,
        entrantTeacher: null,
        consultTeacher: null,
        entryTime: null,
        astTraceDate: null,
        nextTraceTime: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询潜在用户列表 */
    getList() {
      this.loading = true;
      listProspects(this.queryParams).then(response => {
        this.prospectsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        age: null,
        wechat: null,
        qq: null,
        phone: null,
        sex: null,
        workYears: null,
        graduationTime: null,
        channel: null,
        status: null,
        isOldCadetsRecom: null,
        referrers: null,
        degreeIntent: null,
        degreeDiscipline: null,
        degreeClasses: null,
        entrantTeacher: null,
        consultTeacher: null,
        entryTime: null,
        astTraceDate: null,
        nextTraceTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加潜在用户";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getProspects(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改潜在用户";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateProspects(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addProspects(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除潜在用户编号为"' + ids + '"的数据项？').then(function() {
        return delProspects(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('teacher/prospects/export', {
        ...this.queryParams
      }, `prospects_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
